package com.pubinfo.passbook.common.utils;

import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.AbstractVerticalCellStyleStrategy;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.IndexedColors;

/**
 * @ClassName HeadStyleWriteHandler
 * @Author hty
 * @Date 2022/6/30 0030 15:14
 * @Version 1.0
 **/
@Slf4j
public class HeadStyleWriteHandler extends AbstractVerticalCellStyleStrategy {
    /**
     * 操作列
     */
    private int columnIndexes;

    public HeadStyleWriteHandler(int columnIndexes) {
        this.columnIndexes = columnIndexes;
    }

    @Override
    protected WriteCellStyle headCellStyle(Head head) {

        // 获取样式实例
        WriteCellStyle headWriteCellStyle = new WriteCellStyle();
        // 获取字体实例
        WriteFont headWriteFont = new WriteFont();
        // 设置字体样式
        headWriteFont.setFontName("宋体");
        // 设置字体大小
        headWriteFont.setFontHeightInPoints((short) 14);
        // 边框
        headWriteFont.setBold(true);
        // 设置表头单元格必填时为红色
        if (columnIndexes == head.getColumnIndex()) {
            headWriteFont.setColor(IndexedColors.RED.getIndex());
        }else {
            headWriteFont.setColor(IndexedColors.BLACK.getIndex());
        }
        headWriteCellStyle.setWriteFont(headWriteFont);
        return headWriteCellStyle;
    }
}
